# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: https://docs.scrapy.org/en/latest/topics/item-pipeline.html


# useful for handling different item types with a single interface
from itemadapter import ItemAdapter
from tool import dbutil

class CollectPipeline:
    def process_item(self, item, spider):
        creator_id = item['creator_id']
        if creator_id == None or len(creator_id) == 0:
            return
        # creator
        if "creator_nick" in item.keys():
            dbutil.insertCreator(
                creator_id, item["platform"], item["creator_nick"], item["creator_desc"])
        
        # video
        if "creator_nick" in item.keys():
            item.pop("creator_nick")
            item.pop("creator_desc")
        dbutil.insertVideo(item)

        return item
